﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>

<html lang="en">
	<head>
		<base href="<%=basePath%>">
<!-- 		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> -->
		<meta charset="utf-8" />
		<title>付款管理</title>
		<meta name="description" content="" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
		
		<link rel="stylesheet" href="static/ace/css/bootstrap.css" />
		<link rel="stylesheet" href="static/ace/css/font-awesome.css" />
		
		<!-- text fonts -->
		<link rel="stylesheet" href="static/ace/css/ace-fonts.css" />
		<!-- ace styles -->
		<link rel="stylesheet" href="static/ace/css/ace.css" class="ace-main-stylesheet" id="main-ace-style" />
				<link rel="stylesheet" type="text/css" href="plugins/websocketInstantMsg/ext4/resources/css/ext-all.css">
		<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/ext-all-debug.js"></script>
		<script type="text/javascript" src="static/js/jquery-1.7.2.js" />
		<script type="text/javascript">
			$(top.hangge());
		</script>
	</head>
		 
	<body class="no-skin">
		<!-- /section:basics/navbar.layout -->
<!-- 		<div class="main-container" id="main-container"> -->
			
<!-- 		</div> -->
	<div id="receipt"></div>
<!-- 	<div id="receiptgrid"></div> -->
	</body>
	<script type="text/javascript">
	Ext.onReady(function () {
		
		var store = Ext.create('Ext.data.Store', {
			fields: ["payment_app_code","amount","settlement_dept","currency","receipt_amount","paymentAmount","payment_app_dept","is_cost_audit","is_frozen","is_submit","is_income_loan","payment_app_person"],
			pageSize: 10,  //页容量5条数据
			//是否在服务端排序 （true的话，在客户端就不能排序）
			remoteSort: false,
			remoteFilter: true,
			proxy: {
				type: 'ajax',
				url: '<%=basePath%>payment/findPayment',
				reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
					type: 'json', //返回数据类型为json格式
					root: 'result.list',  //数据
					totalProperty: 'result.total' //数据总条数
				}
			},
			sorters: [{
				property: 'ordeId',
				direction: 'desc'
			}],
			autoLoad:{start:0,limit:10},
		});
		var store1 = Ext.create('Ext.data.Store', {
			fields: ["payment_app_code","bill_code","invoice_code","payment_app_dept","currency","is_cost_audit",
			         "payment_amount","early_payment","amount","remaining_balance","is_advance"
			         ],
			pageSize: 10,  //页容量5条数据
			//是否在服务端排序 （true的话，在客户端就不能排序）
			remoteSort: false,
			remoteFilter: true,
			proxy: {
				type: 'ajax',
				url: '<%=basePath%>payment/findPaymentDetail',
				reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
					type: 'json', //返回数据类型为json格式
					root: 'result.list',  //数据
					totalProperty: 'result.total' //数据总条数
				}
			},
			sorters: [{
				property: 'ordeId',
				direction: 'desc'
			}],
			autoLoad:{start:0,limit:10},
		});
		  var c1 = Ext.create('Ext.container.Container', {
				layout: 'column',
				defaults: { labelAlign: 'left', labelWidth: 60 },
				items: [
					{id:"startDate1",xtype: 'textfield', name: 'startDate1',columnWidth: 1/5,padding: '5px',fieldLabel: '付款单号'},
// 					{id:"startDate2",xtype: 'textfield', name: 'startDate2', columnWidth:  1/5,padding: '5px', fieldLabel: '单位'},
// 					{id:"startDate3",xtype: 'textfield', name: 'startDate2', columnWidth:  1/5,padding: '5px', fieldLabel: '收款日期'},
// 					{id:"startDate4",xtype: 'textfield', name: 'startDate2', columnWidth:  1/5,padding: '5px', fieldLabel: '收款部门'},
					
					{xtype: "button",minWidth:70,padding: '5px',icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "查询",handler: function(){
						var payment_app_code = Ext.getCmp('startDate1').getValue();
						var store = Ext.getCmp('grid').getStore();
						store.on('beforeload', function(store,options) {  
					            var new_params = {  
					            		payment_app_code:payment_app_code
					            };  
						//这里apply一下实现新的proxy  
					            Ext.apply(store.proxy.extraParams,new_params);  
					        });  
						//对store重新载入  
					        store.load();
					}}
					]
			});
		var grid = Ext.create('Ext.grid.Panel', {
// 			renderTo: "receipt",
			store: store,
			id:'grid',
			title:"对应成本信息内容",
			height: 330,
			stripeRows:true,
			columnLines: true,
			selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
			columns: [
				{text: 'ID', dataIndex: 'ID',hidden:true},
				{text: '付款单号', dataIndex: 'payment_app_code', align: 'left', maxWidth: 100 ,locked: true},
				{text: '单位', dataIndex: 'settlement_dept', maxWidth: 200 ,locked:true},
				{text: '付款金额', dataIndex: 'amount', maxWidth: 80},
				{text: '借款金额', dataIndex: 'paymentAmount', maxWidth: 80},
				{text: '收款金额', dataIndex: 'receipt_amount', maxWidth: 80},
				{text: '币制', dataIndex: 'currency', align: 'left', minWidth: 80},
				{text: '部门', dataIndex: 'payment_app_dept', maxWidth: 80},
				{text: '申请人', dataIndex: 'payment_app_person', maxWidth: 80},
				{text: '是否审核1是0否', dataIndex: 'is_cost_audit',hidden:true},
				{text: '是否冻结1是0否', dataIndex: 'is_frozen',hidden:true},
				{text: '是否提交审批1是0否', dataIndex: 'is_submit',hidden:true},
				{text: '是否借款1借款0收入', dataIndex: 'is_income_loan',hidden:true},
				
			],
			bbar: [{
				xtype: 'pagingtoolbar',
				store: store,
				displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
				emptyMsg: "没有数据",
				beforePageText: "当前页",
				afterPageText: "共{0}页",
				displayInfo: true,
				pageSize:10
			}],
			listeners: {
				'itemclick': function (view, record, item, index, e) {
					var store = Ext.getCmp('receiptgrid').getStore();
					store.on('beforeload', function(store,options) {  
				            var new_params = {  
				            		payment_app_code:record.data.payment_app_code,
				            		is_income_loan:record.data.is_income_loan
				            };  

				            Ext.apply(store.proxy.extraParams,new_params);  
				        });  
				        store.load();  
				}
			},
			tbar: [
			       {text: '付款审核', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/table_refresh.png',handler: function(){
			    	   var records = grid.getSelectionModel().getSelection();
// 			    	  alert(records[0].data.is_cost_audit);
			    	   if(records.length==0){
			       			Ext.Msg.alert("提示","请选择需要审核的发票");return;
			       		}
			       		if(records.length>1){
			       			Ext.Msg.alert("提示","只能审核一张发票");return;
			       		}
			    	   if(records[0].data.is_cost_audit==1){
			    		   Ext.Msg.alert("提示","已审核，不能再次审核");return;
			    	   }
			    	   if(records[0].data.is_frozen==1){
			    		   Ext.Msg.alert("提示","已冻结，不能审核");return;
			    	   }
			    	   if(records[0].data.is_submit==1){
			    		   Ext.Msg.alert("提示","已提交审批，不能审核");return;
			    	   }
			    	  
			    	   Ext.Ajax.request({
	  						url:'<%=basePath%>payment/updatePaymentInfo',
	  						params:{
	  							payment_app_code:records[0].data.payment_app_code,is_cost_audit:1
	  						},
	  						timeout:5000,
	  						success:function(response){
	  							store.load();
	  							Ext.Msg.alert("成功","审核成功!");
	  						},
	  						failure:function(response){
	  							Ext.Msg.alert("错误","请求异常!");
	  						}
	  					});
			    	   
			       }},
			       {text: '付款冻结', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/table_refresh.png',handler: function(){
			    	   var records = grid.getSelectionModel().getSelection();
			    	   
			    	   if(records.length==0){
			       			Ext.Msg.alert("提示","请选择需要冻结的发票");return;
			       		}
			       		if(records.length>1){
			       			Ext.Msg.alert("提示","只能冻结一张发票");return;
			       		}
			    	   Ext.Ajax.request({
	  						url:'<%=basePath%>payment/updatePaymentInfo',
	  						params:{
	  							payment_app_code:records[0].data.payment_app_code,is_frozen:1
	  						},
	  						timeout:5000,
	  						success:function(response){
	  							store.load();
	  							Ext.Msg.alert("成功","付款冻结成功!");
	  						},
	  						failure:function(response){
	  							Ext.Msg.alert("错误","请求异常!");
	  						}
	  					});
			    	   
			       }},
			       {text: '提交审批', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/table_refresh.png',handler: function(){
			    	   var records = grid.getSelectionModel().getSelection();
			    	   if(records[0].data.is_frozen==1){
			    		   Ext.Msg.alert("提示","已冻结，不能提交审批");return;
			    	   }
			    	   if(records.length==0){
			       			Ext.Msg.alert("提示","请选择需要提交审批的发票");return;
			       		}
			       		if(records.length>1){
			       			Ext.Msg.alert("提示","只能审批一张发票");return;
			       		}
			    	   Ext.Ajax.request({
	  						url:'<%=basePath%>payment/updatePaymentInfo',
	  						params:{
	  							payment_app_code:records[0].data.payment_app_code,is_submit:1
	  						},
	  						timeout:5000,
	  						success:function(response){
	  							store.load();
	  							Ext.Msg.alert("成功","提交审批成功!");
	  						},
	  						failure:function(response){
	  							Ext.Msg.alert("错误","请求异常!");
	  						}
	  					});
			    	   
			       }},{text: '生成制单申请', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/table_refresh.png',handler: function(){
			    	   var records = grid.getSelectionModel().getSelection();
			    	   if(records.length==0){
			       			Ext.Msg.alert("提示","请选择需要生成制单申请的发票");return;
			       		}
			       		if(records.length>1){
			       			Ext.Msg.alert("提示","只能生成一张发票");return;
			       		}
			       		document.location.href="<%=basePath%>common/export/exportExcel?exportType="+"PaymentInfo"+"&payment_app_code="+records[0].data.payment_app_code+"&settlement_dept="+encodeURI(records[0].data.settlement_dept)
			       }}]
		});
		var receiptgrid = Ext.create('Ext.grid.Panel', {
// 			renderTo: "receiptgrid",
			store: store1,
			id:'receiptgrid',
			height: 330,
			title:"付款内容",
			stripeRows:true,
			columnLines: true,
			selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
			columns: [
				{text: 'ID', dataIndex: 'ID',hidden:true},
				{text: '付款单号', dataIndex: 'payment_app_code', align: 'left', maxWidth: 100 ,locked: true},
				{text: '业务编号', dataIndex: 'bill_code', maxWidth: 200 ,locked:true},
				{text: '费用项目', dataIndex: 'containerOwner', maxWidth: 80},
				{text: '发票号', dataIndex: 'invoice_code', maxWidth: 80},
				{text: '部门', dataIndex: 'payment_app_dept', maxWidth: 80},
				{text: '币制', dataIndex: 'currency', align: 'left', minWidth: 80},
				{text: '完税金额', dataIndex: 'payment_amount', maxWidth: 80},
				{text: '前期付款', dataIndex: 'early_payment', maxWidth: 80},
				{text: '本次付款', dataIndex: 'amount', maxWidth: 80},
				{text: '余额', dataIndex: 'remaining_balance', maxWidth: 80},
				{text: '是否预付', dataIndex: 'is_advance', maxWidth: 80},
				{text: '审核状态', dataIndex: 'is_cost_audit', maxWidth: 80}
			],
			bbar: [{
				xtype: 'pagingtoolbar',
				store: store1,
				displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
				emptyMsg: "没有数据",
				beforePageText: "当前页",
				afterPageText: "共{0}页",
				displayInfo: true
			}],
			listeners: {
				'itemclick': function (view, record, item, index, e) {
//                Ext.MessageBox.alert("标题", record.data.cataId);
				}
			},
			tbar: []
		});
		 var panel = new Ext.Panel({
	            frame: true,
// 	            layout:"form",
// 	            width: 260,
// 	            height: 130,
// 	            labelWidth: 70,
	            title: "审核",
	            renderTo:"receipt",
	            items:[c1,grid,receiptgrid],

	            
	        });
	});
	</script>
</html>